let desc = document.querySelector('.desc')
let img = document.querySelector('.show>img')
let title = document.querySelector('.title')
let price = document.querySelector('.price')
let btn = document.querySelector('.btn')

init()

function init() {
    initValue()
}


async function initValue() {
    let params = {
        url: "/goods/item",
        query: {
            id: sessionStorage.getItem('goods_id')
            // id: getParams('goods_id')
        }
    }
    let res = await axios.get(params)
    console.log(res)
    if (res.code == 1) {
        console.log(res);
        desc.innerHTML = res.info.goods_introduce
        img.src = res.info.img_big_logo
        title.innerHTML = res.info.title
        price.innerHTML = res.info.price
    }
}
btn.onclick = async () => {
    // 判断登录了没有  
    if (cookie.getItem('token')) {
        // 发送请求 加入购物车 
        let params = {
            url: '/cart/add',
            query: {
                id: cookie.getItem('userId'),
                goodsId: sessionStorage.getItem('goods_id')
            }
        }
        let res = await axios.post(params)
        console.log(res)
        if (res.code == 1) {
            alert(res.message)
        }
    } else {
        // 提醒登录 
        alert('你还没有登录！请登录以后再操作！')
        location.href = '../html/login.html'
    }
}






